<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Admin_model extends CI_Model{

    /**
     * 添加
     * @param $data
     */
    public function add($data){
        $this->db->insert('admin',$data);
    }

    /**
     * 获取表
     * @return mixed
     */
    public function getlist(){
        $data = $this->db->get('admin')->result_array();
        //var_dump($data);
        return $data;
    }

    /**
     * 获取数据
     * @param $id
     * @return mixed
     */
    public function get($id){
        $data = $this->db->where(array('id' => $id))->get('admin')->result_array();
        return $data;
    }

    /**
     * @param $name
     * @param $psw
     * @return bool
     */
    public function login($name,$psw){
        $data = $this->db->where(array('admin_name' => $name, 'admin_psw' => md5($psw)))->get('admin')->row_array();
        if (empty($data))
            return false;
        return true;
    }

    /**
     * 修改
     */
    public function update($id,$data){
        $this->db->update('admin',$data,array('id'=>$id));
    }

    /**
     * 删除
     */
    public function  del($id){
        $this->db->delete('admin',array('id' => $id));
    }
}